package com.changli01.string.exer2;

import org.junit.Test;

public class Mytrim implements trimtest{

    @Override
    public String trimOfMe(String str) {
        String result = "";
        int startindex = 0;
        int endindex = 0;
        for (int i = 0; i < str.length(); i++) {
            if (str.charAt(i) == ' ') {
                continue;
            }
            if (str.charAt(i) != ' ') {
                startindex = i;
                break;
            }
        }
        for (int i = str.length()-1; i >=0 ; i--) {
            if (str.charAt(i) == ' ') {
                continue;
            }
            if (str.charAt(i) != ' ') {
                endindex = i;
                break;
            }
        }
//        System.out.println(startindex+" "+endindex);
        result = str.substring(startindex, endindex+1);
        return result;
    }
    @Test
    public void test(){
        String s1 = "    abc        a              s           ";
//        System.out.println(s1.length());
//        System.out.println(s1.substring(4,16));
        System.out.println(trimOfMe(s1));

    }
}


interface trimtest {
    public String trimOfMe(String str);

}